#include "utils.h"

namespace cyclone::parser
{
    static const auto SkippedContextId = std::set<short>{
        FormalParser::ContextIdEos,
    };

    static const auto TerminalsSkip = std::set<std::string>{
        "[",
        "]",
        "(",
        ")",
        "{",
        "}",
        ";",
        ",",
        "?",
        "?.",
        ":",
        "...",
        ".",
        "${",
        "@",
    };
    static const std::set<std::string> kReservedKeyWord = {
        "abstract",
        "boolean",
        "byte",
        "char",
        "class",
        "double",
        "enum",
        "export",
        "extends",
        "final",
        "float",
        "goto",
        "implements",
        "int",
        "interface",
        "long",
        "native",
        "package",
        "private",
        "protected",
        "public",
        "short",
        "static",
        "super",
        "synchronized",
        "throws",
        "transient",
        "volatile",
        "const",
        "import",
        "eval",
        "arguments",
        "implements",
        "interface",
        "let",
        "yield",
    };
    bool Utils::shouldIgnore(antlr4::tree::ParseTree *tree)
    {
        return tree ? shouldIgnore(tree, tree->getContextId()) : true;
    }

    bool Utils::shouldIgnore(antlr4::tree::ParseTree *tree, ssize_t index)
    {
        if (!tree || INVALID_INDEX == index)
            return true;
        if (TERMINAL_NODE_INDEX == index)
            return TerminalsSkip.end() != TerminalsSkip.find(tree->getText());
        return SkippedContextId.end() != SkippedContextId.find(index);
    }

    const std::set<std::string> &Utils::getReservedKeywords()
    {
        return kReservedKeyWord;
    }

    std::string Utils::getRuleName(int ruleIndex)
    {
        switch (ruleIndex)
        {
        case FormalParser::RulePattern:
            return "pattern";
        case FormalParser::RuleVariableDeclarator:
            return "variableDeclarator";
        default:
            return std::string();
        }
    }
    
    std::string Utils::getNonSemanticErrorInfoTip()
    {
        return "Unexpected token";
    }

    
} // namespace cyclone::parser

